package windows;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Vector;
import main.*;

import base.Button;
import base.Window;

public class coffee extends Window {
	public int hour = 12;
	public int min = 30;
	//am==-1 pm==1
	public int ampm = 1;
	public boolean water=true;
	public boolean grounds =true;
	int amount2=0;
	
	
	private Vector<Button> buttons = new Vector<Button>( );
	public coffee( )
	{
		super( "Coffee" , "Favorites" , "Kitchen[0]" );
		//buttons.add( new Button( "Button 1" , new Point( 25 , 12 ) , "Images/bunny.png" ) );
		//buttons.add( new Button( "Button 2" , new Point( 50 , 50 ) , "Images/bunny.png" ) );
		
		buttons.add( new Button( "Hup" , new Point( 5 , 25 ) , "Images/bunny.png",false ,true ) );
		buttons.add( new Button( "Mup" , new Point( 63 , 25 ) , "Images/bunny.png" ,false ,true) );
		buttons.add( new Button( "Aup" , new Point(115 , 25 ) , "Images/bunny.png" ,false ,true) );
		buttons.add( new Button( "Hdown" , new Point( 5 , 100 ) , "Images/bunny.png",false ,true ) );
		buttons.add( new Button( "Mdown" , new Point( 63 , 100 ) , "Images/bunny.png" ,false ,true) );
		buttons.add( new Button( "Adown" , new Point(115 ,100 ) , "Images/bunny.png",false ,true ) );
		int centerX = Window.width + (Window.width - Telecommando.width)>>1;
		buttons.add( new Button( "Go" , new Point(centerX-16 ,260 ) , "Images/bunny.png",false ,true ) );
		System.out.println(Telecommando.width);
		
		
	}
	@Override
	public void draw(Graphics2D g2d) {
		for( Button but : buttons )
			but.draw( g2d );
		g2d.setColor(Color.white);
		Font Old = g2d.getFont();
		Font NEW = new Font("SWEET", Font.PLAIN, 32);
		Font NEW2 = new Font("SWEET2", Font.PLAIN, 16);
		Font NEW3 = new Font("SWEET3", Font.PLAIN, 22);
		g2d.setFont(NEW);
		
		if(ampm==1)
		{
			String output = "";
			if( hour < 10 )
				output += "0";
			output += hour;
			output += " : ";
			if( min < 10 )
				output += "0";
			output += min;
			g2d.drawString( output + " PM", 0, 90);
		}else{
			String output = "";
			if( hour < 10 )
				output += "0";
			output += hour;
			output += " : ";
			if( min < 10 )
				output += "0";
			output += min;
			g2d.drawString(output + " AM", 0, 90);
		}
			g2d.setFont(NEW3);
			g2d.drawString( "Make Coffee At", 0, 20);
			g2d.setFont(NEW2);
			g2d.drawString("Has Water", 0, 150);
			if(water)
			{
				g2d.setColor(Color.green);
				g2d.drawString("Yes", 0, 175);	
			}else
			{
				g2d.setColor(Color.red);
				g2d.drawString("No", 0, 175);
			}
			
			g2d.setColor(Color.white);
			g2d.drawString("Has Grounds", 0, 200);
			if(grounds)
			{
				g2d.setColor(Color.green);
				g2d.drawString("Yes", 0, 225);	
			}else
			{
				g2d.setColor(Color.red);
				g2d.drawString("No", 0, 225);
			}
			g2d.setColor(Color.white);
			//g2d.drawString("Has Water", 0, 150);
			g2d.drawString("Start Making Coffee", 0, 250);
			g2d.setFont(Old);
		
	}

	boolean gestureHour = false;
	boolean gestureMin = false;
	boolean gestureAMPM = false;
	@Override
	public void fingerPressed(Point location) {
		if((location.x>5&&location.x<37)&&(location.y>57&&location.y<99))
		{
			gestureHour = true;
			return;
		}
		if((location.x>63&&location.x<95)&&(location.y>57&&location.y<99))
		{
			gestureMin = true;
			return;
		}
		if((location.x>115&&location.x<147)&&(location.y>57&&location.y<99))
		{
			gestureAMPM = true;
			return;
		}
		
		for( Button but : buttons )
		{
			if( but.press( location.x , location.y ) )
			{
				System.out.println(but.getName());
				if( but.getName( ).equals( "Hup" ) )
				{
					hour++;
					if(hour==13)
					{
						hour=1;
						//ampm=ampm*-1;
					}
					if(hour==12)
					{
						ampm=ampm*-1;
					}
					
				}
				if( but.getName( ).equals( "Mup" ) )
				{
					min++;
					if(min==60)
					{
						++hour;
						min=0;
						if(hour==13)
						{
							hour=1;
							//ampm=ampm*-1;
						}
						if(hour==12)
						{
							ampm=ampm*-1;
						}
					}
				
					
				}
				if( but.getName( ).equals( "Aup" ) )
				{
					
						ampm=ampm*-1;
					
				}
					 
				if( but.getName( ).equals( "Hdown" ) )
				{
					hour--;
					if(hour==0)
					{
						hour=12;
						//ampm=ampm*-1;
					}
					if(hour==12)
					{
						ampm=ampm*-1;
					}
					
				}
				if( but.getName( ).equals( "Mdown" ) )
				{
					min--;
					if(min==0)
					{
						--hour;
						min=59;
						if(hour==0)
						{
							hour=12;
							//ampm=ampm*-1;
						}
						if(hour==12)
						{
							ampm=ampm*-1;
						}
					}
				
					
				}
				if( but.getName( ).equals( "Adown" ) )
				{
					
						ampm=ampm*-1;
					
				}
				if( but.getName( ).equals( "Go" ) )
				{
					
						if(grounds ==true)
						{
							grounds =false;
						}else{
							grounds =true;
						}
						if(water ==true)
						{
							water =false;
						}else{
							water =true;
						}
						
					
				}
				return;
			}
		}
	}

	@Override
	public void fingerReleased(Point location) {
		for( Button but : buttons )
			but.release( );
		gestureHour = false;
		gestureMin=false;
		gestureAMPM=false;
	}

	@Override
	public void gestureHorizontal(int amount) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void gestureVertical(int amount) {
		// TODO Auto-generated method stub
		
		if( gestureHour )
		{
			
			if( amount < 0 )
			amount=100000000+amount;
			
			if(amount!=0&& amount%10==1&&amount>amount2)
			{
				hour--;
				if(hour==0)
				{
					hour=12;
					//ampm=ampm*-1;
				}
				if(hour==12)
				{
					ampm=ampm*-1;
				}
			}
			if(amount!=0&& amount%10==1&&amount<amount2)
			{
				hour++;
				if(hour==13)
				{
					hour=1;
					//ampm=ampm*-1;
				}
				if(hour==12)
				{
					ampm=ampm*-1;
				}
			}
			amount2=amount;
		}
		if(gestureMin)
		{
			if( amount < 0 )
				amount=100000000+amount;
			if(amount!=0&& amount%6==1&&amount>amount2)
			{
				min--;
				if(min==0)
				{
					--hour;
					min=59;
					if(hour==0)
					{
						hour=12;
						//ampm=ampm*-1;
					}
					if(hour==12)
					{
						ampm=ampm*-1;
					}
				}
			}
			if(amount!=0&& amount%6==1&&amount<amount2)
			{
				min++;
				if(min==60)
				{
					++hour;
					min=0;
					if(hour==13)
					{
						hour=1;
						//ampm=ampm*-1;
					}
					if(hour==12)
					{
						ampm=ampm*-1;
					}
				}
			
			}
			amount2=amount;
		}
		
		if(gestureAMPM)
		{
			if( amount < 0 )
				amount=100000000+amount;
			if(amount!=0&& amount%20==1&&amount<amount2)
			{
				ampm=ampm*-1;
			}
		}
		
	}
	

}
